import { createApp } from "vue";
import ElementPlus from "element-plus";
import "element-plus/theme-chalk/index.css";
import "element-plus/theme-chalk/display.css"; // 引入基于断点的隐藏类
import "normalize.css"; // css初始化
import "./assets/style/common.scss"; // 公共css
import App from "./App.vue";
import store from "./store";
import router from "./router";
import { ElMessage } from "element-plus";
import { Tabbar, TabbarItem, Icon } from "vant";
// 统一追加url的基础路径
import { createHttp, onHttpError } from "./utils/requests";
createHttp({ baseURL: import.meta.env.VITE_BASE_URL });
// 统一 Http Status Code Error 处理
import { ElNotification } from "element-plus";
onHttpError(({ status, message }) => {
  if (status === 401) {
    ElMessage.error("请先登录");
    return router.push({ name: "login" });
  }
  ElNotification({
    title: "错误",
    message,
    type: "error",
  });
});

const app = createApp(App)
  .use(ElementPlus, { size: store.state.app.elementSize })
  .use(store)
  .use(router)
  .use(Tabbar)
  .use(TabbarItem)
  .use(Icon);
app.mount("#app");
